home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / Tcl.n < prev    next >
Encoding:
Text File  |  1995-02-22  |  6.9 KB  |  193 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994-1995 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) Tcl.n 1.120 95/02/22 14:37:19
  9. '
  10. .so man.macros
  11. .de UL
  12. \\$1\l'|0\(ul'\\$2
  13. ..
  14. .HS Tcl tcl
  15. .BS
  16. .SH NAME
  17. Tcl \- Summary of Tcl language syntax.
  18. .BE
  19.  
  20. .SH DESCRIPTION
  21. .LP
  22. The following rules define the syntax and semantics of the Tcl language:
  23. .IP [1]
  24. A Tcl script is a string containing one or more commands.
  25. Semi-colons and newlines are command separators unless quoted as
  26. described below.
  27. Close brackets are command terminators during command substitution
  28. (see below) unless quoted.
  29. .IP [2]
  30. A command is evaluated in two steps.
  31. First, the Tcl interpreter breaks the command into \fIwords\fR
  32. and performs substitutions as described below.
  33. These substitutions are performed in the same way for all
  34. commands.
  35. The first word is used to locate a command procedure to
  36. carry out the command, then all of the words of the command are
  37. passed to the command procedure.
  38. The command procedure is free to interpret each of its words
  39. in any way it likes, such as an integer, variable name, list,
  40. or Tcl script.
  41. Different commands interpret their words differently.
  42. .IP [3]
  43. Words of a command are separated by white space (except for
  44. newlines, which are command separators).
  45. .IP [4]
  46. If the first character of a word is double-quote (``"'') then
  47. the word is terminated by the next double-quote character.
  48. If semi-colons, close brackets, or white space characters
  49. (including newlines) appear between the quotes then they are treated
  50. as ordinary characters and included in the word.
  51. Command substitution, variable substitution, and backslash substitution
  52. are performed on the characters between the quotes as described below.
  53. The double-quotes are not retained as part of the word.
  54. .IP [5]
  55. If the first character of a word is an open brace (``{'') then
  56. the word is terminated by the matching close brace (``}'').
  57. Braces nest within the word: for each additional open
  58. brace there must be an additional close brace (however,
  59. if an open brace or close brace within the word is
  60. quoted with a backslash then it is not counted in locating the
  61. matching close brace).
  62. No substitutions are performed on the characters between the
  63. braces except for backslash-newline substitutions described
  64. below, nor do semi-colons, newlines, close brackets,
  65. or white space receive any special interpretation.
  66. The word will consist of exactly the characters between the
  67. outer braces, not including the braces themselves.
  68. .IP [6]
  69. If a word contains an open bracket (``['') then Tcl performs
  70. \fIcommand substitution\fR.
  71. To do this it invokes the Tcl interpreter recursively to process
  72. the characters following the open bracket as a Tcl script.
  73. The script may contain any number of commands and must be terminated
  74. by a close bracket (``]'').
  75. The result of the script (i.e. the result of its last command) is
  76. substituted into the word in place of the brackets and all of the
  77. characters between them.
  78. There may be any number of command substitutions in a single word.
  79. Command substitution is not performed on words enclosed in braces.
  80. .IP [7]
  81. If a word contains a dollar-sign (``$'') then Tcl performs \fIvariable
  82. substitution\fR:  the dollar-sign and the following characters are
  83. replaced in the word by the value of a variable.
  84. Variable substitution may take any of the following forms:
  85. .RS
  86. .TP 15
  87. \fB$\fIname\fR
  88. \fIName\fR is the name of a scalar variable;  the name is terminated
  89. by any character that isn't a letter, digit, or underscore.
  90. .TP 15
  91. \fB$\fIname\fB(\fIindex\fB)\fR
  92. \fIName\fR gives the name of an array variable and \fIindex\fR gives
  93. the name of an element within that array.
  94. \fIName\fR must contain only letters, digits, and underscores.
  95. Command substitutions, variable substitutions, and backslash
  96. substitutions are performed on the characters of \fIindex\fR.
  97. .TP 15
  98. \fB${\fIname\fB}\fR
  99. \fIName\fR is the name of a scalar variable.  It may contain any
  100. characters whatsoever except for close braces.
  101. .RE
  102. .LP
  103. There may be any number of variable substitutions in a single word.
  104. Variable substitution is not performed on words enclosed in braces.
  105. .IP [8]
  106. If a backslash (``\e'') appears within a word then
  107. \fIbackslash substitution\fR occurs.
  108. .VS
  109. In all cases but those described below the backslash is dropped and
  110. the following character is treated as an ordinary
  111. character and included in the word.
  112. .VE
  113. This allows characters such as double quotes, close brackets,
  114. and dollar signs to be included in words without triggering
  115. special processing.
  116. The following table lists the backslash sequences that are
  117. handled specially, along with the value that replaces each sequence.
  118. .RS
  119. .VS
  120. .TP 6
  121. \e\fBa\fR
  122. Audible alert (bell) (0x7).
  123. .VE
  124. .TP 6
  125. \e\fBb\fR
  126. Backspace (0x8).
  127. .TP 6
  128. \e\fBf\fR
  129. Form feed (0xc).
  130. .TP 6
  131. \e\fBn\fR
  132. Newline (0xa).
  133. .TP 6
  134. \e\fBr\fR
  135. Carriage-return (0xd).
  136. .TP 6
  137. \e\fBt\fR
  138. Tab (0x9).
  139. .TP 6
  140. \e\fBv\fR
  141. Vertical tab (0xb).
  142. .TP 6
  143. \e\fB<newline>\fIwhiteSpace\fR\fR
  144. .VS
  145. A single space character replaces the backslash, newline, and all
  146. white space after the newline.
  147. This backslash sequence is unique in that it is replaced in a separate
  148. pre-pass before the command is actually parsed.
  149. This means that it will be replaced even when it occurs between
  150. braces, and the resulting space will be treated as a word separator
  151. if it isn't in braces or quotes.
  152. .VE
  153. .TP 6
  154. \e\e
  155. Backslash (``\e'').
  156. .TP 6
  157. \e\fIooo\fR
  158. The digits \fIooo\fR (one, two, or three of them) give the octal value of
  159. the character.
  160. .TP 6
  161. \e\fBx\fIhh\fR
  162. .VS
  163. The hexadecimal digits \fIhh\fR give the hexadecimal value of
  164. the character.  Any number of digits may be present.
  165. .VE
  166. .RE
  167. .LP
  168. Backslash substitution is not performed on words enclosed in braces,
  169. except for backslash-newline as described above.
  170. .IP [9]
  171. If a hash character (``#'') appears at a point where Tcl is
  172. expecting the first character of the first word of a command,
  173. then the hash character and the characters that follow it, up
  174. through the next newline, are treated as a comment and ignored.
  175. The comment character only has significance when it appears
  176. at the beginning of a command.
  177. .IP [10]
  178. Each character is processed exactly once by the Tcl interpreter
  179. as part of creating the words of a command.
  180. For example, if variable substitution occurs then no further
  181. substitutions are performed on the value of the variable;  the
  182. value is inserted into the word verbatim.
  183. If command substitution occurs then the nested command is
  184. processed entirely by the recursive call to the Tcl interpreter;
  185. no substitutions are perfomed before making the recursive
  186. call and no additional substitutions are performed on the result
  187. of the nested script.
  188. .IP [11]
  189. Substitutions do not affect the word boundaries of a command.
  190. For example, during variable substitution the entire value of
  191. the variable becomes part of a single word, even if the variable's
  192. value contains spaces.
  193.